<template>
    <div class="login-box">
      <div class="video-bg">
        <video muted autoplay loop onclick="return false;">
          <source src="../../assets/jarvis.mp4" type="video/mp4">
        </video>
      </div>
      <div class="line">
        <input type="text" v-model="user.account" placeholder="Please input your user name">
      </div>
      <div class="line">
        <input type="password" v-model="user.password" placeholder="Please input your password">
      </div>
      <div class="line" style="margin-top: 20px;">
        <button class="login-button" @click="login">登录</button>
      </div>
    </div>
</template>

<script>
    import {login} from "../../apis/auth";
    import Token from "../../libs/token";

    export default {
        name: "login-box",
        data () {
            return {
                user: {
                    account: '',
                    password: ''
                }
            }
        },
        methods: {
            login()
            {
                login(this.user.account, this.user.password).then((res) => {
                    if(res.code === 20000) {
                        Token.setToken(res.data.api_token);
                        let query  = this.$route.query;
                        if(query.hasOwnProperty('form')) {
                            return this.$router.push({
                                path: this.$route.query.from
                            })
                        }

                        return this.$router.push({
                            name: 'index'
                        })
                    }
                })
            }
        }
    }
</script>

<style scoped>
  .login-box {
    padding: 40px;
    background-color: rgba(100, 187, 255, 0.47);
    border-radius: 5px;
  }

  .line {
    height: 50px;
  }

  .line > input{
    height: 40px;
    box-sizing: border-box;
    width: 300px;
    padding: 0px 10px;
  }

  .login-button {
    width: 300px;
    height: 40px;
    background-color: rgb(0, 190, 248);
    border: 1px solid #fff;
    border-radius: 4px;
    color: white;
    outline: 0;
  }

  .login-button:active {
    box-shadow: 0 0 4px 2px #ccc inset;
  }

  .login-button:hover {
    background-color: rgb(17, 155, 168);
  }

  .video-bg {
    position: fixed;
    z-index: -1;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
  }

  .video-bg video {
    position: fixed;
    top: 0;
    left: 0;
    min-width: 100%;
    min-height: 100%;
  }

</style>
